package kr.nexmore.slmsample2.view.listsample;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

public class ListPart implements SelectionListener {
	private Text name_txt;
	private Text add_txt;
	private Text phone_txt;
	private Table table;

	public ListPart() {
	}

	/**
	 * Create contents of the view part.
	 */
	@PostConstruct
	public void createControls(Composite parent) {
		parent.setLayout(new FormLayout());

		name_txt = new Text(parent, SWT.BORDER);
		FormData fd_text = new FormData();
		name_txt.setLayoutData(fd_text);

		add_txt = new Text(parent, SWT.BORDER);
		FormData fd_text_1 = new FormData();
		add_txt.setLayoutData(fd_text_1);

		phone_txt = new Text(parent, SWT.BORDER);
		FormData fd_text_2 = new FormData();
		phone_txt.setLayoutData(fd_text_2);

		Label lblNewLabel = new Label(parent, SWT.NONE);
		fd_text_2.top = new FormAttachment(lblNewLabel, -3, SWT.TOP);
		fd_text_1.top = new FormAttachment(lblNewLabel, -3, SWT.TOP);
		fd_text.top = new FormAttachment(lblNewLabel, -3, SWT.TOP);
		fd_text.left = new FormAttachment(lblNewLabel, 10);
		FormData fd_lblNewLabel = new FormData();
		fd_lblNewLabel.left = new FormAttachment(0, 10);
		lblNewLabel.setLayoutData(fd_lblNewLabel);
		lblNewLabel.setText("\uC774\uB984");

		Label label = new Label(parent, SWT.NONE);
		fd_text_1.left = new FormAttachment(label, 6);
		label.setText("\uC8FC\uC18C");
		FormData fd_label = new FormData();
		fd_label.top = new FormAttachment(lblNewLabel, 0, SWT.TOP);
		fd_label.left = new FormAttachment(name_txt, 6);
		label.setLayoutData(fd_label);

		Label label_1 = new Label(parent, SWT.NONE);
		fd_text_2.left = new FormAttachment(label_1, 18);
		fd_lblNewLabel.top = new FormAttachment(0, 42);
		label_1.setText("\uC804\uD654\uBC88\uD638");
		FormData fd_label_1 = new FormData();
		fd_label_1.top = new FormAttachment(lblNewLabel, 0, SWT.TOP);
		fd_label_1.left = new FormAttachment(add_txt, 6);
		label_1.setLayoutData(fd_label_1);

		Button button = new Button(parent, SWT.NONE);
		button.addSelectionListener(this);
		button.setText("\uC785\uB825");
		FormData fd_button = new FormData();
		fd_button.top = new FormAttachment(lblNewLabel, -5, SWT.TOP);
		fd_button.left = new FormAttachment(phone_txt, 27);
		fd_button.right = new FormAttachment(100, -10);
		button.setLayoutData(fd_button);

		table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		FormData fd_table = new FormData();
		fd_table.top = new FormAttachment(name_txt, 49);
		fd_table.bottom = new FormAttachment(100, -10);
		fd_table.left = new FormAttachment(0, 71);
		fd_table.right = new FormAttachment(100, -95);
		table.setLayoutData(fd_table);

		TableColumn tableColumn = new TableColumn(table, SWT.NONE);
		tableColumn.setWidth(100);
		tableColumn.setText("\uC774\uB984");

		TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
		tableColumn_1.setWidth(100);
		tableColumn_1.setText("\uC8FC\uC18C");

		TableColumn tableColumn_2 = new TableColumn(table, SWT.NONE);
		tableColumn_2.setWidth(100);
		tableColumn_2.setText("\uC804\uD654\uBC88\uD638");

	}

	@PreDestroy
	public void dispose() {
	}

	@Focus
	public void setFocus() {
		// TODO Set the focus to control
	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		// TODO Auto-generated method stub
		/*
		 * TableColumn column = new TableColumn (table, SWT.NONE, index);
		 * column.setText ("Column " + index + "a");
		 */

		TableItem item = new TableItem(table, 0);
		String[] txt_value = { name_txt.getText(), add_txt.getText(),
				phone_txt.getText() };
		for (int i = 0; i < table.getColumnCount(); i++) {
			item.setText(i, txt_value[i]);
		}

		System.out.println(name_txt.getText() + add_txt.getText()
				+ phone_txt.getText());

	}

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
		// TODO Auto-generated method stub

	}
}
